package bb.lanxing.lib.devices.bici;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class BiciDate {
    private static final DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String getFormatDate(int i, long j) {
        if (i == 1) {
            return format1.format(new Date(j));
        }
        return format1.format(new Date(j));
    }

    public static int timestampToBiciDate(long j) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        calendar.setTimeInMillis(j);
        int i = calendar.get(1);
        int i2 = calendar.get(2);
        int i3 = calendar.get(5);
        int i4 = calendar.get(11);
        int i5 = (i - 2014) << 26;
        int i6 = (i2 + 1) << 22;
        int i7 = i3 << 17;
        int i8 = i4 << 12;
        return (int) (calendar.get(13) + (calendar.get(12) << 6) + i8 + i7 + i6 + (i5 & 4294967295L));
    }

    public static long biciDateToTimestamp(int i) {
        int i2 = ((int) ((i & 4294967295L) >> 26)) + 2014;
        int i3 = (i >> 17) & 31;
        int i4 = (i >> 12) & 31;
        int i5 = (i >> 6) & 63;
        int i6 = i & 63;
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        calendar.set(i2, ((i >> 22) & 15) - 1, i3, i4, i5, i6);
        return calendar.getTimeInMillis();
    }
}
